package com.air.admin.service.imp;


import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.air.admin.dao.AdminPrivilegeDao;
import com.air.admin.service.IAdminPrivilegeService;
import com.air.admin.vo.PrivilegeQueryRequestVO;
import com.air.common.service.imp.BaseServiceImp;
import com.air.common.util.QueryCondition;
import com.air.common.util.QueryExpression;
import com.air.common.vo.PageResultListVO;


@Service("adminPrivilegeService")
public class AdminPrivilegeServiceImp extends BaseServiceImp implements
		IAdminPrivilegeService, InitializingBean {
	
	private final String simpleModeQueryStringTemplate="upper(CODE) like '%{queryString}%' or upper(DESCRIPTION) like '%{queryString}%'";
	
	@Autowired
	AdminPrivilegeDao adminPrivilegeMapper;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		this.baseDao = adminPrivilegeMapper;
	}

	@Override
	
	public PageResultListVO queryInSimpleMode(QueryCondition condition,
			Integer pageNum,Integer pageLimit,String queryString) throws Exception{
		
		
		
		if (queryString!=null&&queryString.trim().length()>0){
			queryString = queryString.toUpperCase();
			String simpleModeQueryCondition = simpleModeQueryStringTemplate.replace("{queryString}", queryString);
			condition.addManualCondition(simpleModeQueryCondition);
		}
		return this.queryByCondition(condition, pageNum, pageLimit);
		
	}

	@Override
	public PageResultListVO queryInAdvanceMode(QueryCondition condition,
			Integer pageNum, Integer pageLimit,
			PrivilegeQueryRequestVO queryRequestVO) throws Exception {
		
		if (queryRequestVO.getCode().length()>0){
			condition.addQueryCondition("code", queryRequestVO.getCode(), QueryExpression.LIKE);
		}
		
		if (queryRequestVO.getDescription().length()>0){
			condition.addQueryCondition("description", queryRequestVO.getDescription(), QueryExpression.LIKE);
		}
		
		return queryByCondition(condition, pageNum, pageLimit);
	}
	
	
	
}
